#include <stdio.h>

#define MAXSIZE 10

typedef struct student {
	char name[MAXSIZE + 1];
	char sno[MAXSIZE + 1];
	int grade;
} student;

int main() {
	setbuf(stdout, NULL);

	// NOTE: Variable declaration
	int n;
	int max, min, max_index, min_index;


	// NOTE: Inputs
	// STEP: 获取学生总数
	scanf("%d", &n);

	// STEP: 实例化student类型的动态数组stu[]
	student stu[n];

	// STEP: 初始化动态数组stu[]
	for (int i = 0; i < n; ++i) {
		scanf("%s %s %d", stu[i].name, stu[i].sno, &stu[i].grade);
	}


	// NOTE: Process
	// STEP: 定义最高分和最低分是第一位学生
	max = stu[0].grade;
	min = stu[0].grade;
	max_index = min_index = 0;

	// STEP: 遍历剩余的学生信息，更新最高分和最低分学生的索引
	for (int i = 1; i < n; ++i) {
		if (stu[i].grade > max) {
			max_index = i;
			max = stu[i].grade;
		}

		if (stu[i].grade < min) {
			min_index = i;
			min = stu[i].grade;
		}
	}


	// NOTE: Outputs
	printf("%s %s\n", stu[max_index].name, stu[max_index].sno);
	printf("%s %s\n", stu[min_index].name, stu[min_index].sno);


	// NOTE: Ending
	return 0;
}